package com.niuxiaofa.newlaw.Network;

import com.google.gson.Gson;
import com.niuxiaofa.newlaw.Bean.BannerBean;

import java.util.Map;

import okhttp3.MediaType;
import okhttp3.RequestBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;


public class NewsPresenter {

    /**
     *
     */
    public static void bannerListByType(Map map, interface_getStartBannerByType interface_getStartBannerByType) {

        Gson gson = new Gson();

        String json=gson.toJson(map);

        RequestBody body = RequestBody.create(MediaType.parse("application/json; charset=utf-8"),json);

        Call<BannerBean> call = ServiceManager.getInstance().creat(ApiService.class).bannerListByType(body);
        call.enqueue(new Callback<BannerBean>() {
            @Override
            public void onResponse(Call<BannerBean> call, Response<BannerBean> response) {
                //判断请求是否成功
                if (response.isSuccessful()) {
                    BannerBean bannerBean = (BannerBean) response.body();
                    interface_getStartBannerByType.addData(bannerBean);
                }
            }

            @Override
            public void onFailure(Call<BannerBean> call, Throwable t) {
//            Log.e("链接错误", t.getMessage());

            }
        });

    }

    public interface interface_getStartBannerByType {
        void addData(BannerBean u);
    }





}
